
/* Functions that draws different objects such as
 * Players
 * Flags (actually balls)
 * Bullets
 * Worlds
 */
#include <stdio.h>
#include <stdlib.h>
#include "draw.h"
#include "SDL.h"
#include "worldObjects.h"

/* Affiche un sprite à partir de sa structure */
void displaySprite(SDL_Surface *screen, SDL_Surface *sprite, int x, int y)
{
    /* Rectangle décrivant le sprite actuel à afficher */
    //SDL_Rect src;

    /* Rectangle contenant les coordonnées du sprite à l'écran */
    SDL_Rect dst;

    /* Coordonnées à l'écran de la nouvelle position */
    dst.x = x;
    dst.y = y;

    /* On recopie le rectangle du sprite sur le buffer d'affichage */
    SDL_BlitSurface(sprite, NULL/*&src*/, screen, &dst);
}

void loadResourses (void)
{
	char* filename = "gfx/triangle.png";
	char* filename2 = "gfx/triangle2.png";
	tmp = IMG_Load(filename);
    /*if(tmp==NULL)
    { 
    	printf("je suis null\n"); 
    	exit(3);
    }*/
	
    // on charge notre image Triangle
	/*spriteTriangle = (SPRITE*)malloc(sizeof(SPRITE));
	spriteTriangle->posX = 240-(TRIANGLE_WIDTH/2);
	spriteTriangle->posY = 136-(TRIANGLE_WIDTH/2);
    spriteTriangle->source = SDL_DisplayFormat(tmp);
    SDL_FreeSurface(tmp);*/
    
    player = (PLAYER*)malloc(sizeof(PLAYER));
    player->posX = 240-(TRIANGLE_WIDTH/2);
    player->posY = 136-(TRIANGLE_WIDTH/2);
    player->source = SDL_DisplayFormat(tmp);
    SDL_FreeSurface(tmp);
    tmp2 = IMG_Load(filename2);
  
    // La couleur fushia est transparente
    SDL_SetColorKey(player->source,SDL_SRCCOLORKEY,SDL_MapRGB(player->source->format, 0xff, 0x00, 0xff));
}

/*void drawFlags()//FLAGS f)
{
	
}*/

void drawPlayer(PLAYER *p)
{
	displaySprite(screen, p->source, p->posX, p->posY);
}
